package com.yan.test;

import org.hibernate.Session;
import org.hibernate.Transaction;
import org.junit.Test;

import com.yan.domain.Role;
import com.yan.domain.User;
import com.yan.utils.HibernateUtils;

public class Demo2 {
	
	@Test
	public void run1() {
		Session session = HibernateUtils.getCurrentSession();
		Transaction tr = session.beginTransaction();
		User u1 = new User();
		u1.setUsername("张三");
		User u2 = new User();
		u2.setUsername("李四");
		
		Role r1 = new Role();
		r1.setRname("经理");
		Role r2 = new Role();
		r2.setRname("演员");
		
		u1.getRoles().add(r1);
		u1.getRoles().add(r2);
		
		u2.getRoles().add(r2);
		
		session.save(u1);
		session.save(u2);
		
		tr.commit();
		
	}

}
